package com.ocom.nettyxf.vo;

import com.ocom.common.utils.CommonUtil;
import com.ocom.common.utils.NumConvertUtil;
import lombok.Data;

/**
 * @Description: 参数更新
 * @Author: 朱晖
 * @Date: 2022/10/21
 **/
@Data
public class ParamVo {

	//响应结果
	String code = "0000";

	//JobID
	String jobId = "000000000000";

	//参数个数
	String sum = "00";

	ParamPayVo paramPayVo = new ParamPayVo();

	ParamMachVo paramMachVo = new ParamMachVo();

	public String getHexStr() throws Exception {
		if (CommonUtil.isNull(jobId) || jobId.equals("0")) {
			jobId = "000000000000";
		}
		String result = code
				+ jobId;

		//参数个数
		Integer paramCount = 1;
		if (paramPayVo.getUse()) {
			paramCount++;
		}
		if (paramMachVo.getUse()) {
			paramCount++;
		}
		sum = NumConvertUtil.IntToHexStringNum(paramCount, 2);

		result += sum;

		//1-每次最大上传记录   名称1 长度1 每次1条
		result += "01000101";

		if (paramPayVo.getUse()) {
			//4个字节
			result += paramPayVo.getName();
			result += "0004";
			result += paramPayVo.getHeartBeatNum();
			result += paramPayVo.getCancelFlag();
			result += paramPayVo.getPayTime();
			result += paramPayVo.getPayInterval();
		}

		if (paramMachVo.getUse()) {
			//4个字节
			result += paramMachVo.getName();

			String command = "";
			command += paramMachVo.getMachNamelen();
			command += paramMachVo.getMachName();
			command += paramMachVo.getMerchNamelen();
			command += paramMachVo.getMerchName();
			command += paramMachVo.getConsType();
			command += paramMachVo.getDeviceMode();
			command += paramMachVo.getQrMaker();
			command += paramMachVo.getCardFlag();
//			command += paramMachVo.getCosumerMode();
//			command += paramMachVo.getFixPriKeyMoney();


			String mealParagroup = NumConvertUtil.IntToHexStringNum(paramMachVo.getMealVoList().size(), 2);

			command += mealParagroup;

			for (MealVo mealVo : paramMachVo.getMealVoList()) {
				command += mealVo.getMealNo();
				command += mealVo.getMealName();
				command += mealVo.getCosumerMode();
				command += mealVo.getBeginTime();
				command += mealVo.getEndTime();
				command += mealVo.getMealMoney();
				command += mealVo.getAccountType();
				command += mealVo.getVoucherMode();
			}

			result += NumConvertUtil.IntToHexStringNum(command.length()/2, 4);

			result += command;
		}

		return result;
	}

	public void setJobId(String jobId) {
		if (jobId.length() < 12) {
			int len = jobId.length();
			for (int i = len; i < 12; i++) {
				jobId = "0"+jobId;
			}
		}
		this.jobId = jobId;
	}

}
